<?php get_header(); ?>

<script>
  $(document).ready(function(){
    $(".date").collapse({show: function(){
        this.animate({
          opacity: 'toggle', 
          height: 'toggle'
        }, 300);
      },
      hide : function() {
        this.animate({
            opacity: 'toggle', 
            height: 'toggle'
        }, 300);
      }
    });
    
    $('.date .field:eq(0)').css('display', 'block');
    $('.date h4:eq(0)').attr('class', 'active');
  });
</script>

<div class="content-top"></div>
<div class="content-bottom">
  <div class="wrapper">
    <?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
    
    <div class="content-sidebar">
      <div class="sidebar-title">
        <h3>NEWS</h3>
        <h4>NEWS ARCHIEVE</h4>
      </div>
      
      <div class="sidebar-content">
        <div class="date">
          <?php 
          $counter =0;
          
          foreach(get_the_category() as $category)
          { $thecat = $category->cat_ID; } ?>
          <?php query_posts('cat=' . $thecat); ?>
          <?php if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
          
          <?php
            // check if final post
            $counter++;
            if($counter == $wp_query->post_count){
              $counter = 0;
              
            };
          ?>
          
          <?php $year = the_date('F Y', '', '', FALSE); ?>
            <?php 
               // If your year hasn't been echoed earlier in the loop, echo it now
               if ($year !== $year_check) {
                
                if($year_check != ''){
                  echo '</div>';
                }
                
                echo "<h4>" . $year . "</h4>";
                echo '<div class="field">';
               }
               // Now that your year has been printed, assign it to the $year_check variable
               $year_check = $year;
            ?>
            
              <div class="post">
                <h5><?php the_time('j F Y') ?></h5>
                <?php 
                  $mycontent = getWords(get_the_content(), 20);
                  echo apply_filters('the_content', $mycontent); 
                ?>
                <a href="<?php echo get_permalink(); ?>">Read More...</a>
              </div><!-- end .post-wrap -->

          <?php endwhile; ?>
          <?php endif; ?>
          </div>
        </div>
      </div>
    </div>
    <div class="news-content">
      
        <?php $args = array(
          'numberposts'     => 5,
          'category'        => $thecat,
          'orderby'         => 'post_date',
          'order'           => 'DESC',
          'post_status'     => 'publish' ); 
        ?> 
        <?php $posts_array = get_posts( $args ); 
        foreach($posts_array as $post){ ?>
          <div class="news-big-content">
            <h4><?php echo date('d/n/Y', strtotime($post->post_date)); ?></h4>
            
            <?php if ( has_post_thumbnail() ) { ?>
              <div class="picture-frame">
                <?php the_post_thumbnail(); ?>
              </div>
            <?php } ?>
            <h3><a href="<?php echo get_permalink(); ?>"><?php echo $post->post_title; ?></a></h3>
            <?php 
              $mycontent = getWords($post->post_content, 150);
              echo apply_filters('the_content', $mycontent);  
            ?>
            <p><a href="<?php echo get_permalink(); ?>">Read More...</a></p>
          </div>
        <?php  }  ?> 
    </div>
  </div>
</div>

<?php get_footer(); ?>
